package com.ruoyi.asset.maintenance.controller;


import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.asset.maintenance.domain.bo.IntegratedMaintenanceBo;
import com.ruoyi.asset.maintenance.domain.bo.MaintenanceStatisticsBo;
import com.ruoyi.asset.maintenance.domain.vo.IntegratedMaintenanceVo;
import com.ruoyi.asset.maintenance.domain.vo.MaintenanceCommunityCountVo;
import com.ruoyi.asset.maintenance.domain.vo.MaintenanceCommunityMapVo;
import com.ruoyi.asset.maintenance.domain.vo.MaintenanceWorkStatisticsVo;
import com.ruoyi.asset.maintenance.service.IIntegratedMaintenanceService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.system.domain.vo.SysOssVo;
import com.ruoyi.system.service.ISysOssService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 一体化维护管养
 *
 * @author 12276
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/asset/maintenance")
public class IntegratedMaintenanceController extends BaseController {

    private final IIntegratedMaintenanceService maintenanceService;

    /**
     * 获取一体化维护管养-管理范围导入模板
     */
    @SaIgnore()
    @Log(title = "一体化维护管养范围导入", businessType = BusinessType.IMPORT)
    @RepeatSubmit()
    @PostMapping(value = "/importData")
    public R<List<String>> importData(@RequestParam(name = "excelUrl") String excelUrl) {
        List<String> list = this.maintenanceService.importExcel(excelUrl);

        if (list == null) {
            return R.fail();
        } else {
            return R.ok(list);
        }
    }

    /**
     * 获取一体化维护管养-管理范围导入模板
     */
    @SaIgnore()
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil.exportExcel(new ArrayList<>(), "一体化维护管养管理范围导入模板", IntegratedMaintenanceVo.class, response);
    }

    /**
     * 删除一体化维护管养范围
     */
    @SaIgnore()
    @DeleteMapping("/deleteMaintenance/{ids}")
    public R<Void> deleteMaintenance(@NotEmpty(message = "主键不能为空")
                                          @PathVariable Set<Long> ids) {
        int count = this.maintenanceService.deleteMaintenance(ids);

        return toAjax(count >= 0 ? 1 : count);
    }

    /**
     * 查询一体化维护管养范围
     */
    @SaIgnore()
    @GetMapping("/queryMaintenance")
    public TableDataInfo<IntegratedMaintenanceVo> queryMaintenance (IntegratedMaintenanceBo searchBo, PageQuery pageQuery) {
        return this.maintenanceService.queryMaintenance(searchBo, pageQuery);
    }

    /**
     * 导出一体化维护管养范围
     */
    @SaIgnore()
    @Log(title = "一体化维护管养范围导出", businessType = BusinessType.EXPORT)
    @PostMapping("/exportMaintenance")
    public void exportMaintenance(IntegratedMaintenanceBo searchBo, HttpServletResponse response) {
        List<IntegratedMaintenanceVo> list = this.maintenanceService.exportMaintenance(searchBo);

        ExcelUtil.exportExcel(list, "一体化维护管养范围", IntegratedMaintenanceVo.class, response);
    }

    @SaIgnore()
    @GetMapping("/maintenanceCount")
    public R<MaintenanceStatisticsBo> maintenanceCount() {
        MaintenanceStatisticsBo lampCount = maintenanceService.getMaintenanceCount();
        return R.ok(lampCount);
    }

    @SaIgnore()
    @GetMapping("/maintenanceCommunityCount")
    public R<Map> maintenanceCommunityCount() {
        Map map = maintenanceService.getMaintenanceCommunityCount();
        return R.ok(map);
    }

    /**
     * 查询智慧大屏一体化维修玉塘街道全社区
     * @param date
     * @return
     */
    @SaIgnore()
    @GetMapping("/maintenanceCommunity")
    public R<List<MaintenanceCommunityCountVo>> maintenanceCommunity(String date) {
        date = "2024-03-13";
        List<MaintenanceCommunityCountVo> maintenanceCountByCommunity = maintenanceService.getMaintenanceCountByCommunity(date);
        return R.ok(maintenanceCountByCommunity);
    }

    /**
     * 查询智慧大屏一体化维修今日作业统计与百分比
     * @param date
     * @return
     */
    @SaIgnore()
    @GetMapping("/maintenanceWorkByDate")
    public R<MaintenanceWorkStatisticsVo> maintenanceWorkByDate(String date) {
        date = "2024-03-13";
        MaintenanceWorkStatisticsVo maintenanceWorkByDate = maintenanceService.getMaintenanceWorkByDate(date);
        return R.ok(maintenanceWorkByDate);
    }

    /**
     * 查询智慧大屏一体化维修今日作业统计与百分比 指定社区
     * @param date 日期
     * @param community 社区
     * @return
     */
    @SaIgnore()
    @GetMapping("/maintenanceWorkByDateAndCommunity")
    public R<MaintenanceWorkStatisticsVo> maintenanceWorkByDateAndCommunity(String date,String community) {
        date = "2024-03-13";
        MaintenanceWorkStatisticsVo maintenanceWorkByDate = maintenanceService.getMaintenanceWorkByDateAndCommunity(date,community);
        return R.ok(maintenanceWorkByDate);
    }

    /**
     * 查询智慧大屏一体化维修按社区区分
     * @param community
     * @param date
     * @return
     */
    @SaIgnore()
    @GetMapping("/communityByDate")
    public R<MaintenanceCommunityMapVo> communityByDate(String community, String date) {
        date = "2024-03-13";
        MaintenanceCommunityMapVo communityByDate = maintenanceService.getCommunityByDate(community, date);
        return R.ok(communityByDate);
    }
}
